//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//

import { mapGetters, mapActions } from "vuex";
import _ from "lodash";
import template from "./askRoadTemplate";
const { render, staticRenderFns } = template;

export default {
  render,
  staticRenderFns,
  props: [],
  data() {
    return {
      showRoadNav: true,
      showLongRoad: false,
      leftBarArr: [],
      navArr: ["大小问路", "单双问路", "长龙"],
      roadActive: "dxRoad",
      checkedNavIndex: 0,
      posKey: 0,
      arrMinLen: [18, 21],
      lottery_type: this.$route.query.lottery_type,
      bigRoad: [],
      smallRoad: [],
      bigEyes: [],
      tlRoad: [],
      zpRoad: [],
      LongDragonList: [],
      showNavPanel: false,
    };
  },
  created() {
    this._getLongDragon();
  },
  mounted() {
    var roomTop = document.getElementById("roomTop");
    var askRoadPanel = document.getElementById("askRoadPanel");
    askRoadPanel.style.height =
      document.documentElement.clientHeight - roomTop.offsetHeight + "px";
    this.initLeftBar();
    this.getData(this.roadActive);
  },
  computed: {
    ...mapGetters(["roomData"]),
  },
  methods: {
    _getLongDragon() {
      let vm = this;
      let dataName = {};
      dataName.token = localStorage.getItem("token");
      dataName.lottery_type = vm.lottery_type;
      vm.$http
        .post(vm.urlRequest + "?m=api&c=app&a=getLongDragon", dataName)
        .then((res) => {
          if (res.status == 0) {
            vm.LongDragonList = res.data;
          }
        });
    },
    initLeftBar: function () {
      var lottery_type = this.$route.query.lottery_type;
      if (
        lottery_type == 1 ||
        lottery_type == 3 ||
        lottery_type == 17 ||
        lottery_type == 18 ||
        lottery_type == 20 ||
        lottery_type == 22
      ) {
        this.showRoadNav = false;
      } else if (
        lottery_type == 2 ||
        lottery_type == 4 ||
        lottery_type == 9 ||
        lottery_type == 14
      ) {
        this.leftBarArr = [
          "冠亚和",
          "冠军",
          "亚军",
          "第三名",
          "第四名",
          "第五名",
          "第六名",
          "第七名",
          "第八名",
          "第九名",
          "第十名",
        ];
      } else if (
        lottery_type == 5 ||
        lottery_type == 6 ||
        lottery_type == 11 ||
        lottery_type == 21
      ) {
        this.leftBarArr = [
          "猜总和",
          "第一球",
          "第二球",
          "第三球",
          "第四球",
          "第五球",
        ];
      } else if (lottery_type == 7 || lottery_type == 8 || lottery_type == 24) {
        this.leftBarArr = [
          "正码总和",
          "正1特",
          "正2特",
          "正3特",
          "正4特",
          "正5特",
          "正6特",
          "特码",
        ];
      } else if (lottery_type == 10) {
        this.leftBarArr = [
          "猜总和",
          "第一张",
          "第二张",
          "第三张",
          "第四张",
          "第五张",
        ];
      } else if (lottery_type == 13 || lottery_type == 19) {
        this.leftBarArr = ["猜总和", "第一骰", "第二骰", "第三骰"];
      }
    },
    getData: function (name) {
      this.roadActive = name;
      var that = this;
      let askType = 1;
      if (name == "dsRoad") {
        askType = 2;
      } else if (name == "clRoad") {
        this.$vux.toast.show({
          text: "暂未开放，尽请期待",
        });
        return;
      }
      this.$vux.loading.show();
      let apiUrl = "";
      if (
        this.lottery_type == 1 ||
        this.lottery_type == 3 ||
        this.lottery_type == 17 ||
        this.lottery_type == 18 ||
        this.lottery_type == 20 ||
        this.lottery_type == 22
      ) {
        apiUrl = "?m=api&c=askload&a=createLoad28";
      } else if (
        this.lottery_type == 2 ||
        this.lottery_type == 4 ||
        this.lottery_type == 9 ||
        this.lottery_type == 14
      ) {
        apiUrl = "?m=api&c=askload&a=createLoadPK10";
      } else if (
        this.lottery_type == 5 ||
        this.lottery_type == 6 ||
        this.lottery_type == 11 ||
        this.lottery_type == 21
      ) {
        apiUrl = "?m=api&c=askload&a=createLoadSSC";
      } else if (this.lottery_type == 7 || this.lottery_type == 8 || this.lottery_type == 24) {
        apiUrl = "?m=api&c=askload&a=createLoadLHC";
      } else if (this.lottery_type == 10) {
        apiUrl = "?m=api&c=askload&a=createLoadNN";
      } else if (this.lottery_type == 13 || this.lottery_type == 19) {
        apiUrl = "?m=api&c=askload&a=createLoadSB";
      }
      this.$http
        .post(this.urlRequest + apiUrl, {
          ask_type: askType,
          lottery_type: this.lottery_type,
          token: this.token,
          pos_key: this.posKey,
        })
        .then((result) => {
          that.$vux.loading.hide();
          that.bigRoad = that.addLength(
            result.data.big_load,
            that.arrMinLen[0]
          );
          that.smallRoad = that.addLength(
            result.data.small_load,
            that.arrMinLen[1]
          );
          that.bigEyes = that.addLength(
            result.data.dyz_load,
            that.arrMinLen[1]
          );
          that.tlRoad = that.addLength(result.data.zl_load, that.arrMinLen[0]);
          that.zpRoad = that.addLength(result.data.zp_load, that.arrMinLen[0]);
          setTimeout(function () {
            var panelList = document.getElementsByClassName("dlPanel");
            let newArr = [];
            for (var i = 0; i < panelList.length; i++) {
              newArr.push(panelList[i]);
            }
            for (var j = 0; j < newArr.length; j++) {
              var panel = newArr[j];
              if (panel.scrollWidth > 550) {
                panel.scrollLeft = panel.scrollWidth;
              }
            }
          });
        });
    },
    addLength: function (arr, length) {
      for (var i = 0; i < arr.length; i++) {
        var flag = true;
        if (arr[i].length < length) {
          arr[i].push([]);
          this.addLength(arr, length);
        } else if (arr[i].length > length && flag) {
          flag = false;
          arr[i].push([]);
          arr[i].push([]);
        }
      }
      return arr;
    },
    closeAskRoad: function () {
      var obj = this.roomData;
      obj.showAskRoad = false;
      this.$store.commit("setRoomData", obj);
    },
    changeLeftBar: function (index) {
      this.posKey = index;
      if (this.checkedNavIndex == 0) {
        this.getData("dxRoad");
      } else if (this.checkedNavIndex == 1) {
        this.getData("dsRoad");
      }
      this.showNavPanel = false;
    },
    changeBar: function (index) {
      this.checkedNavIndex = index;
      this.showLongRoad = false;
      if (index == 0) {
        this.getData("dxRoad");
      } else if (index == 1) {
        this.getData("dsRoad");
      } else if (index == 2) {
        this.showLongRoad = true;
      }
    },
  },
  components: {},
  watch: {},
  deactivated() {},
  beforeDestroy() {},
};

// WEBPACK FOOTER //
// ./src/components/room/askRoad/askRoad.vue
